package first.group.ssh.packet;

import first.group.ssh.SSHConsts;
import first.group.ssh.packet.reader.StringReader;
import first.group.ssh.packet.writer.StringWriter;
import java.io.IOException;
import java.nio.ByteBuffer;

public class IgnorePacket extends Packet {
    
    public final byte[] payload;

    public IgnorePacket(byte[] payload) {
        super(SSHConsts.SSH_MSG_IGNORE);
        this.payload = payload;
    }

    public static PacketParser<IgnorePacket> PARSER = new Parser();

    private static class Parser extends PacketParser<IgnorePacket> {

        @Override
        public IgnorePacket parse(ByteBuffer buffer) throws IOException {
            var payload = StringReader.readByteArray(buffer);
            if (payload == null) {
                return null;
            }
            return new IgnorePacket(payload);
        }
    }

    @Override
    public void write(ByteBuffer buffer) {
        StringWriter.writeByteArray(buffer, payload);
    }
}
